#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
	pid_t id= fork();
	if(id == 0)
	{
		//子进程
		int cnt =3;
		while(1)
		{
			sleep(3);
			printf("我是一个子进程，pid:%d,ppid:%d\n",getpid(),getppid());
			sleep(1);
			cnt--;
			int *p =0;
			*p=100;
			
		}
		exit(10);

	}
	
	//父进程
	//1.子进程退出
	//2.子进程没退出呢
	//
	int status =0;
	pid_t rid = waitpid(id,&status,0);
	if(rid >0)
	{
		printf("wait success,rid:%d,exit code :%d,exit signal:%d\n",rid,(status>>8)&0xFF,status&0x7F);//rid
	}
	else
	{
		printf("wait success:%d: %s\n",errno,strerror(errno));
	}
	
	return 0;

}

//void fun()
//{
//	printf("fun begin\n");
//	_exit(4);
//
//	printf("fun end!\n");
//
//}

//int main()
//{
//	//fun();
//	printf("main!");
//	sleep(2);
//
//	exit(23);
//	
////	int a=10;
////	
////	a/= 0;
////
////	return 89;
////
////
////	//int i =0;
////	//for(;i<200;i++)
////	//{
////	//	printf("%d->%s\n",i,strerror(i));
////	//}
////	//printf("hello world\n");
////
////	//FILE *fp = fopen("log.txt","r");
////	//if(fp == NULL) return 13;
//
//	//fclose(fp);
//	return 0;
//}
